/*
 * commons is a based project implemented
 * Copyright (C) 2024 Jasmine
 */
package com.easy.core.domain.pojo;

import java.io.Serializable;
import java.util.Objects;

/**
 * A generic class for pairs. tuple Pair
 *
 * @author Jasmine
 * @since 1.0.0
 */
public class Pair<T1, T2> implements Serializable {
    private static final long serialVersionUID = -3986244606585552569L;

    protected T1 first = null;
    protected T2 second = null;

    /**
     * Default constructor.
     */
    public Pair() {}

    /**
     * Constructor
     *
     * @param a operand
     * @param b operand
     */
    public Pair(T1 a, T2 b) {
        this.first = a;
        this.second = b;
    }

    /**
     * Constructs a new pair, inferring the type via the passed arguments
     *
     * @param <T1> type for first
     * @param <T2> type for second
     * @param a first element
     * @param b second element
     * @return a new pair containing the passed arguments
     */
    public static <T1, T2> Pair<T1, T2> newPair(T1 a, T2 b) {
        return new Pair<>(a, b);
    }

    public T1 getFirst() {
        return first;
    }

    public void setFirst(T1 first) {
        this.first = first;
    }

    public T2 getSecond() {
        return second;
    }

    public void setSecond(T2 second) {
        this.second = second;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;
        Pair<?, ?> pair = (Pair<?, ?>)o;
        return Objects.equals(first, pair.first) && Objects.equals(second, pair.second);
    }

    @Override
    public int hashCode() {
        return Objects.hash(first, second);
    }
}
